
#include <string.h>
#include "VInfra/VDebug.h"
#include "VInfra/VThreadpool.h"
#include "VInfra/VTime.h"
#include "VInfra/VDefine.h"

#include "_test_Veda.h"

using namespace Veda;

namespace VedaTest{

static void test_ThreadPool_func1(void* p)
{
	tracef("test_ThreadPool_func1 : %s\n",(char*)p);
	VThread::dumpAllThreads();
	VTime::sleep(1);
}

void test_ThreadPool_func2(void* p)
{
	debugf("test_ThreadPool_func2 : %s\n",(char*)p);
	VThread::dumpAllThreads();
	VTime::sleep(1);
}

class test_ThreadPool
{
public:
	void work1(void* p)
	{
		infof("test_ThreadPool::work1 : %s\n",(char*)p);
		VThread::dumpAllThreads();
		VTime::sleep(1);
	}
	void work2(void* p)
	{
		warnf("test_ThreadPool::work2 : %s\n",(char*)p);
		VThread::dumpAllThreads();
		VTime::sleep(1);
	}
	void work3(void* p)
	{
		errorf("test_ThreadPool::work3 : %s\n",(char*)p);
		VThread::dumpAllThreads();
		VTime::sleep(1);
	}
};
void _test_VThreadPool()
{
	test_ThreadPool test;
	VThreadPool mythreadpool("CM",3);
	for(int i = 0; i<1;i++)
	{
		mythreadpool.run(&test_ThreadPool_func1, (void*)("sala"),"sala");
		mythreadpool.run(&test_ThreadPool_func2, (void*)("mygirl"),"mygirl");
		mythreadpool.run(&test, &test_ThreadPool::work1, (void*)("caicai"), "caicai");
		mythreadpool.run(&test, &test_ThreadPool::work2, (void*)("dongdong"), "dongdong");
		mythreadpool.run(&test, &test_ThreadPool::work3, (void*)("shasha"), "shasha");
	}
	mythreadpool.rename("chen_meng");
	mythreadpool.setCapacity(10);
	for(int i = 0; i<1;i++)
	{
		mythreadpool.run(&test_ThreadPool_func1, (void*)("sala"),"sala");
		mythreadpool.run(&test_ThreadPool_func2, (void*)("mygirl"),"mygirl");
		mythreadpool.run(&test, &test_ThreadPool::work1, (void*)("caicai"), "caicai");
		mythreadpool.run(&test, &test_ThreadPool::work2, (void*)("dongdong"), "dongdong");
		mythreadpool.run(&test, &test_ThreadPool::work3, (void*)("shasha"), "shasha");
	}

	VTime::sleep(5);
}

}

